<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>串口配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../../css/public.css" media="all" />
</head>

<body>
    <br>
    <br>
    <form class="layui-form" action="" lay-filter="serialform">
        <div class="layui-form-item layui-col-md3">
            <label class="layui-form-label">波特率</label>
            <div class="layui-input-block" >
                <select name="BaudRate"  id="BaudRate" lay-filter="BaudRate">
                    <option value=""></option>
                    <option value=1200>1200</option>
                    <option value=2400>2400</option>
                    <option value=4800>4800</option>
                    <option value=9600>9600</option>
                    <option value=115200>115200</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-col-md3">
            <label class="layui-form-label">数据位</label>
            <div class="layui-input-block">
                <select name="DataBits" lay-filter="DataBits">
                    <option value=""></option>
                    <option value=8 selected="">8</option>
                    <option value=9>9</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-col-md3">
            <label class="layui-form-label">停止位</label>
            <div class="layui-input-block">
                <select name="StopBits" lay-filter="StopBits">
                    <option value=""></option>
                    <option value="1" selected="">1</option>
                    <option value="2">2</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-col-md3">
            <label class="layui-form-label">校验位</label>
            <div class="layui-input-block">
                <select name="Parity" lay-filter="Parity">
                    <option value=""></option>
                    <option value="N" selected="">无</option>
                    <option value="E">奇校验</option>
                    <option value="O">偶校验</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">流控制</label>
            <div class="layui-input-block">
                <input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">开关</label>
            <div class="layui-input-block">
                <input type="checkbox" name="switch" lay-skin="switch">
            </div>
        </div>

        <br>
        <br>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="update">获取更新</button>
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="enter">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </form>


    <script type="text/javascript" src="../../layui/layui.js"></script>
    <script type="text/javascript" src="../../js/cache.js"></script>
    <script type="text/javascript">
        layui.use(['element', 'form', 'jquery'], function() {

            var $ = layui.jquery;
            var form = layui.form

            //监听提交
            form.on('submit(update)', function(data) {
                $.ajax({
                    url: "/api/v1/serial",
                    type: "Get",
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
						let baudRate = data.Data.BaudRate
                        console.log(`获取到的数据是：${baudRate}`);	
							$('#BaudRate').val(baudRate)						
                            form.render('select')
                    },
					
                    error: function(data) {
                        console.log("错误")
                    }
                });
            });
            form.on('submit(enter)', function(data) {
                console.log(JSON.stringify(data.field))
                    //return false;
                $.ajax({
                    url: "/api/v1/serial",
                    data: JSON.stringify(data.field),
                    type: "Post",
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        console.log(data.Code);
                    },
                    error: function(data) {
                        console.log("错误")
                    }
                });
            });

        });
    </script>

</body>

</html>